package org.yty.travelagencyredis.service.impl;

import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.yty.travelagencyredis.Dao.ChatGroupMemberDao;
import org.yty.travelagencyredis.model.Entity.ChatGroupMember;
import org.yty.travelagencyredis.service.ChatGroupMemberService;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ChatGroupMemberServiceImpl implements ChatGroupMemberService {
    private final ChatGroupMemberDao chatGroupMemberDao;

    @Override
    public List<ChatGroupMember> getListByChatGroupId(String chatGroupId) {
        return this.chatGroupMemberDao.selectByChatGroupId(chatGroupId);
    }

    @Override
    public boolean save(ChatGroupMember chatGroupMember) {
        if (chatGroupMember.getId() == null){
            chatGroupMember.setId(IdUtil.getSnowflakeNextId());
        }
        chatGroupMember.setCreateTime(LocalDateTime.now());
        chatGroupMember.setUpdateTime(LocalDateTime.now());
        return this.chatGroupMemberDao.insert(chatGroupMember);
    }

    @Override
    public void deleteByChatGroupIdAndChatUserId(String chatGroupId, String chatUserId) {
        this.chatGroupMemberDao.deleteByChatGroupIdAndChatUserId(chatGroupId, chatUserId);
    }

    @Override
    public void deleteByChatGroupId(String chatGroupId) {
        this.chatGroupMemberDao.deleteByChatGroupId(chatGroupId);
    }

    @Override
    public void deleteByChatUserId(String chatUserId) {
        this.chatGroupMemberDao.deleteByChatUserId(chatUserId);
    }
}
